// 1
export type StrBool = 'foo' | 'bar' | null;

// 2
export const StrBool = {
  // 2.1
  Foo: 'foo',
  Bar: 'bar',
  Null: null,
  // 2.1
  is,
  isFoo,
  isBar,
  isNull,
  intoBoolean,
};

// 3
function is(value: unknown): value is StrBool {
  return isFoo(value) || isBar(value) || isNull(value);
}

// 4
function isFoo(value: unknown): value is StrBool {
  return value === StrBool.Foo;
}

function isBar(value: unknown): value is StrBool {
  return value === StrBool.Bar;
}

function isNull(value: unknown): value is StrBool {
  return value === StrBool.Null;
}

// 5
function intoBoolean(value: StrBool): boolean {
  return isFoo(value) || isNull(value);
}
